<%@ page import="java.util.*,SiTuQingYou.vo.*"  language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
    <%String path=request.getContextPath(); %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
<style type="text/css">
#divinfor
{
 width:800px;
margin:auto;
text-align: center;
margin-top:40px;
 

}
ul
{

list-style:none;
margin:auto;
padding:0px;
 
}
img
{
width:500px;
height:200px;

}
li
{
margin-top:10px;
}
#con
{
border-bottom:1px solid gray;
text-align:left;
width:800px;
 
}
#likex
{
width:800px;
 
height:40px;
}
#likex span
{
float:right;
margin-right:20px;
 
}
#com
{
width:800px;
border:1px solid gray;
 
}
#likex>span>a
{
text-decoration: none;
}
#d
{
width:100px;
height:100px;
border:1px solid gray;
}
#temp
{
width:800px;
height:100px;
border:1px solid gray;
display:none;
}
#comtext
{
width:800px;
height:60px;
border:1px solid gray;
}
#temp>input
{
float:right;
width:800px;
height:40px;
}
#author
{
 
text-align: right;
}
#coms
{
background-color:#E0FFFF;
margin-bottom: 5px;
border-bottom: 1px solid gray;
}
</style>

<script type="text/javascript" src="<%=path %>/index/js/jquery-3.3.1.min.js"></script>
<!-- 收藏 -->
<script type="text/javascript">
$(document).ready(load);
function load()
{
   $(document).ready(function(){
	   
	   $("#col").click(function(){
		  var id=$("#col").attr("cid");
		  $.ajax(
				  {
					  url:"<%=path%>/MyCollectionServlet",
					  type:"post",
					  data:"method=checkStrategyCollectionServlet&id="+id,
					  success:function(mes){
						if(mes==2)
							{
							 location.href = "/SiTuQingYou/anotherLogReg/login.jsp";
							}
							if(mes==1)
						    	{
								$("#col").children().css("color","black");
						    	alert("取消收藏")
						    	}
						    if(mes==0)
					    	{
						    $("#col").children().css("color","red");
					    	alert("收藏成功")
					    	}	
							}
				  });
		   
	   });
	   
   });
}
</script>
<!-- 点赞 -->
<script type="text/javascript">
$(document).ready(function(){
	 
	    $("#lik").click(function(){
		  var id=$("#lik").attr("cid");
		  var count=$("#total").html();
		  count=parseInt(count);
		  $.ajax(
				  {
					  url:"<%=path%>/MyCollectionServlet",
					  type:"post",
					  data:"method=checkStrategyLikeServlet&id="+id,
					  success:function(mes){
						if(mes==2)
							{
							 location.href = "/SiTuQingYou/anotherLogReg/login.jsp";
							}
							if(mes==1)
						    	{
								$("#total").html(count-1);
								$("#lik").children().css("color","black");
						     
						    	}
						    if(mes==0)
					    	{
						    $("#total").html(count+1);
						    $("#lik").children().css("color","red");
					     
					    	}	
							}
				  });
		   
	   });
	   
});
</script>
<!-- 得出该攻略总赞数 -->
<script type="text/javascript">
$(document).ready(function(){
	 var id=$("#total").attr("cid");
	 $.ajax(
			  {
				  url:"<%=path%>/MyCollectionServlet",
				  type:"post",
				  data:"method=getToatalLike&id="+id,
				  success:function(mes){
					  $("#total").html(mes);
						}
			  });
	
});
</script>
<!-- 评论 -->
<script type="text/javascript">
  var n=0;
$(document).ready(function(){
	
	$("#comtext").focus(function(){
	$("#comtext").html("");	
	n=1;
	});
		$("#comment").click(function(){
			var dis=$("#temp").css("display");
			if(dis=="none")
				{
				$("#temp").css("display","block");
				$("#sub").click(function(){
			    var text=$("#comtext").val();
			    var zz=/^([\s\S]{1,100})$/;
				var flag=zz.test(text);
				var id=$("#comment").attr("cid");
				if(flag&&n==1)
					{
					$.ajax({
						url:"<%=path%>/MyCommentServlet",
						  type:"post",
						  data:"method=saveComment&text="+text+"&id="+id,
						  success:function(mes){
							 
							  if(mes==0)
								  {
								  location.href = "/SiTuQingYou/anotherLogReg/login.jsp";
								  }
							  else
								  {
								  var newAut=$("<div></div>")
								  newAut.html("by "+mes);
								  newAut.css("text-align","right");
								  newAut.css("border-bottom","1px solid gray");
								  $("#com").prepend(newAut);
								  var newCom=$("<div></div>")
								  newCom.html(text);
								  $("#com").prepend(newCom)
								  alert("发表成功！！");
								  n=0;
								  }
							  
							 
						  }
						
					});
					}
				else
					{
					alert("请按要求输入评论内容！");
					}
					
				});
				}
			else
				{
				
				}
		});
		 
	

	
});


</script>

</head>
<body>
<jsp:include page="header.jsp"></jsp:include>
<jsp:include page="/StrategyServlet"><jsp:param value="getStrategyContent" name="method"/></jsp:include>
 <%Strategy strategy=(Strategy)request.getAttribute("strategy"); %>
 <div id="divinfor">
 <ul>
  <li><h2><%=strategy.getTitle() %></h2></li>
   <li>by <%=strategy.getUser().getUsernickname()%> <%=strategy.getStime() %></li>
 <li><img src="<%=path%>/imagess/<%=strategy.getPhoto()%>"/></li>
 <li id="con" ><%=strategy.getContent() %></li>
  <li id="likex" >
  <span id="comment" cid="<%=strategy.getId()%>"><a href="script:void(0)">评论</a></span>
  <span id="total" cid="<%=strategy.getId()%>">0</span>
  <span id="lik" cid="<%=strategy.getId()%>"><a href="script:void(0)">点赞</a></span>
  <span id="col" cid="<%=strategy.getId()%>"><a href="script:void(0)">收藏</a></span>
  </li>
  <div id="temp">
  <textarea id="comtext">请输入评论内容（不超过100个字符）</textarea>
  <input id="sub" value="发表" type="button"/>
  </div>
  <li id="com" > 
  <jsp:include page="/MyCommentServlet"><jsp:param value="<%=strategy.getId()%>" name="id"/><jsp:param value="findAllCommentByStrategyId" name="method"/></jsp:include>
  <%  ArrayList<Comment> allComment=(ArrayList<Comment>)request.getAttribute("allComment"); %>
  <%
  for(Comment com:allComment)
  {
	  %>
	  <div id="coms">
	  <div ><%=com.getComment() %></div>
	  <div id="author">by <%=com.getUser().getUsernickname() %><%=com.getCommenttime()%> </div>
	  </div>
	  <% 
  }
  %>
  
  </li>
 </ul> 
 </div>
<jsp:include page="footer.jsp"></jsp:include>


</body>
</html>